package cn.gson.school.controller.jiaoxue;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONArray;

import cn.gson.school.dao.jiaoxue.*;
import cn.gson.school.dao.qiantai.TeamStudentDao;
import cn.gson.school.dao.xitong.UserInfoDao;
import cn.gson.school.dao.zhaosheng.InputStudentDao;
import cn.gson.school.entity.jiaoxue.*;
import cn.gson.school.entity.xitong.UserInfoEntity;
import cn.gson.school.entity.zhaosheng.InputStudentEntity;
import cn.gson.school.mappers.jiaoxue.*;

/**
 * 教学模块
 * 
 * @author lc
 */
@Controller
@RequestMapping("/jiaoxue")
public class JiaoXueController {

	@Autowired
	private QinShiDao qinshiDao;

	@Autowired
	private ClassDao classDao;
	@Autowired
	private StudentDao studentDao;

	@Autowired
	private PhaseDao phaseDao;

	@Autowired
	private ZhangJieDao zhangJieDao;

	@Autowired
	private ZhuanBanDao zhuanbanDao;

	@Autowired
	private FangTanDao fangtanDao;

	@Autowired
	private UserInfoDao userInfoDao;

	@Autowired
	private ProjectDao projectDao;

	@Autowired
	private TiMuDao tiMuDao;

	@Autowired
	private ZuoYeDao zuoyeDao;

	@Autowired
	private ZuoYeMappers zuoyeMappers;

	@Autowired
	private ZuoYeClassDao zuoyeClassDao;

	@Autowired
	private ZuoYeTitleDao zuoyeTitleDao;

	@Autowired
	private TiMuMappers timuMappers;

	@Autowired
	private AnswerDao answerDao;

	@Autowired
	private GrandeDao grandeDao;
	
	@Autowired
	private ClassMappers classMappers;
	
	@Autowired
	private TeamDao teamDao;
	
	@Autowired
	private TeamClassDao teamClassDao;
	
	@Autowired
	private TeamStudentDao teamStudentDao; 
	
	@Autowired
	private InputStudentDao inputStudentDao;

	@RequestMapping("/jx-class-list")
	public String classList(Model model) {// 进入班级列表
		Iterable<ClassEntity> list = classDao.findByDelete(1);
		model.addAttribute("classList", list);
		return "jiaoxue/jx-class-list";
	}

	@RequestMapping("/zhuanban/{id}")
	public String zhuanban(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			//根据学生编号来查询学生的现在的班级
			StudentEntity studentEntity=studentDao.findOne(id);
			ClassEntity oldClass=classDao.findOne(studentEntity.getClassId());//获取该学生的现在所在的班级
			model.addAttribute("oldclass", oldClass);
			model.addAttribute("studentEntity",studentEntity);
			model.addAttribute("title",1);
		}
		Iterable<ClassEntity> list = classDao.findByDelete(1);
		model.addAttribute("classList", list);
		return "jiaoxue/jx-add-zhuanban";
	}
	
	
	@RequestMapping({"/jx-add-class","/jx-add-class/{id}"})
	public String addClass(@PathVariable(name = "id", required = false) Long id, Model model) {// 进入添加班级界面
		if (id != null) {// 如果班级编号不为空，则获取该编号的信息，进行编辑
			ClassEntity classEntity = classDao.findOne(id);
			model.addAttribute("classList",classEntity);
			model.addAttribute("classId",classEntity.getClassId() );
			model.addAttribute("classTeacherOne",classEntity.getClassTeacherId().getUserName() );
			model.addAttribute("teacherOne",classEntity.getTeacherId().getUserName() );
		}
		List<Map<String, Object>> classteacher=classMappers.chaXunShenFen("班主任");
		List<Map<String, Object>>  teacher=classMappers.chaXunShenFen("教员");
		model.addAttribute("classteacher", classteacher);
		model.addAttribute("teacher", teacher);
		return "jiaoxue/jx-add-class";
	}

	@RequestMapping({ "/jx-yuejuan", "/jx-yuejuan/{classId}/{zuoyeClassId}" })
	public String yuejuan(@PathVariable(name = "classId", required = false) Long classId,
			@PathVariable(name = "zuoyeClassId", required = false) Long zuoyeClassId, Model model) {
		List<StudentEntity> students = studentDao.findByClassId(classId);
		ZuoYeClassEntity zuoYeClass = zuoyeClassDao.findOne(zuoyeClassId);
		model.addAttribute("students", students);
		model.addAttribute("zuoYeClass", zuoYeClass);

		return "jiaoxue/jx-yuejuan";
	}

	@RequestMapping({ "/jx-start-yuejuan", "/jx-start-yuejuan/{id}/{stuId}" })
	public String startYuejuan(@PathVariable(name = "id", required = false) Long id,
			@PathVariable(name = "stuId", required = false) Long stuId, Model model) {
		System.out.println("学生姓名："+stuId);
		if (id != null && stuId != null) {
			// 获取作业题目
			ZuoYeClassEntity zuoYeClassEntity = zuoyeClassDao.findOne(id);
			Long f = zuoYeClassEntity.getZuoyeId();
			// 根据学生编号和作业编号来获取分数
			GradeEntity gradeEntity = grandeDao.cxGrande(f, stuId);
			if (gradeEntity != null) {
				/*
				 * ============================================柱状图==============================
				 * =====================================
				 */
				List<Integer> score = new ArrayList<Integer>();
				List<String> studentNames = new ArrayList<String>();
				// 获取这次作业中这个班里面的所有学生的成绩
				List<StudentEntity> studentEntities = studentDao.findByClassId(gradeEntity.getStudentinfoId().getClassId());
				for (StudentEntity studentEntity : studentEntities) {
					//GradeEntity c = grandeDao.findByStudentinfoId(studentEntity);
					GradeEntity c=grandeDao.cxGrande(zuoYeClassEntity.getZuoyeId(), studentEntity.getStuId());
					if (c!=null) {
						System.out.println("EEEE:"+c);
						score.add(new Double(c.getSumScore()).intValue());
					}else {
						score.add(0);
					}
					studentNames.add(studentEntity.getStudentName());
				}
				model.addAttribute("studentScore",JSONArray.toJSONString(score));
				model.addAttribute("studentNames",JSONArray.toJSONString(studentNames));
				/*
				 * =============================================================================
				 * ==================================
				 */
				model.addAttribute("grande", gradeEntity);
				// 如果是已经批阅完的练习
				// 获取班级
				ClassEntity classEntity = classDao.findOne(gradeEntity.getStudentinfoId().getClassId());
				String className = classEntity.getClassName();
				model.addAttribute("className", className);
				// 获取作业名称
				String name = gradeEntity.getZuoye().getZuoyeName();
				model.addAttribute("name", name);
				// 获取出卷人
				String userinfoName = gradeEntity.getZuoye().getUserinfo().getUserName();
				model.addAttribute("userinfoName", userinfoName);
				// 获取作业的章节
				ChapterEntity chapterEntity = zhangJieDao.findOne(gradeEntity.getZuoye().getChapterinfo());
				model.addAttribute("chapterEntity", chapterEntity);

				// 获取阶段
				PhaseEntity phaseEntity = phaseDao.findOne(chapterEntity.getPhaseId());
				model.addAttribute("phaseEntity", phaseEntity);
			}
			//获取选择题的总分数
			Integer neirong1=zuoyeMappers.htChaXunFenShu1(stuId, Long.valueOf(f));
			System.out.println("neirong1"+neirong1);
			model.addAttribute("neirong1", neirong1);
			//获取判断题的总分数
			Integer neirong2=zuoyeMappers.htChaXunFenShu2(stuId, Long.valueOf(f));
			System.out.println("neirong2"+neirong2);
			model.addAttribute("neirong2", neirong2);
			// 根据作业班级里的作业编号，去查询作业题目中的题目，对应的题目
			List<ZuoYeTitleEntity> zuoYeTitles = zuoyeTitleDao.findByZuoyeId(zuoYeClassEntity.getZuoyeId());
			List<Object> list1 = new ArrayList<Object>();
			List<Object> list2 = new ArrayList<Object>();
			List<Object> list3 = new ArrayList<Object>();
			// 将该作业下的作业循环读出来，存进新的集合中
			for (ZuoYeTitleEntity zuoYeTitleEntity : zuoYeTitles) {
				// 根据作业题目的对象中的题目编号来获取题目对象
				TitleEntity titleEntity = tiMuDao.findOne(zuoYeTitleEntity.getTitleId());
				System.out.println("titleEntityRR"+titleEntity);
				// 在根据题目题目对象中的题目类型进行分类，分别存进不同的题目集合中
				if ("选择题".equals(titleEntity.getTitleType())) {
					AnswerEntity answerEntity=answerDao.findByStudentIdAndZuoYeIdAndTitleId(Long.valueOf(stuId), Long.valueOf(f), titleEntity.getTitleId());
					if (answerEntity!=null) {
						titleEntity.setTitleType(answerEntity.getAnswer());
					}else {
						titleEntity.setTitleType("");
						titleEntity.setDelete(0);
					}
					list1.add(titleEntity);
				} else if ("判断题".equals(titleEntity.getTitleType())) {
					AnswerEntity answerEntity=answerDao.findByStudentIdAndZuoYeIdAndTitleId(Long.valueOf(stuId), Long.valueOf(f), titleEntity.getTitleId());
					if (answerEntity!=null) {
						titleEntity.setTitleType(answerEntity.getAnswer());
					}else {
						titleEntity.setTitleType("");
						titleEntity.setDelete(0);
					}
					list2.add(titleEntity);
				} else if ("代码题".equals(titleEntity.getTitleType())) {
					AnswerEntity answerEntity=answerDao.findByStudentIdAndZuoYeIdAndTitleId(Long.valueOf(stuId), Long.valueOf(f), titleEntity.getTitleId());
					if (answerEntity!=null) {
						titleEntity.setTitleType(answerEntity.getAnswer());
						titleEntity.setDelete(answerEntity.getScore());
					}else {
						titleEntity.setTitleType("");
					}
					list3.add(titleEntity);
				}
			}
			model.addAttribute("title1", list1);
			model.addAttribute("title2", list2);
			model.addAttribute("title3", list3);
			// 获取选择题和代码题的数量
			Integer size1 = list1.size();
			Integer size2 = list2.size();
			Integer count = size1 + size2;
			Integer count2 = list3.size();
			Integer score = 50 / count;
			model.addAttribute("count1", count);
			model.addAttribute("count3", count2);
			model.addAttribute("score", score);
			// 计算选择题的总分数
			Integer xuanze = (50 / count) * size1;
			model.addAttribute("xuanze", xuanze);
			// 计算判断题的每题得分
			// 用总分100分减去代码题的固定分数在除以代码题的数量就是代码题每一题的分数
			Integer daiMaScore = (100 - 50) / count2;
			model.addAttribute("daiMaScore", daiMaScore);
			// 计算所有的判断题的分数
			Integer panDuan = (50 / count) * size2;
			model.addAttribute("panDuan", panDuan);
			List<AnswerEntity> answer1 = new ArrayList<AnswerEntity>();
			List<AnswerEntity> answer2 = new ArrayList<AnswerEntity>();
			List<AnswerEntity> answer3 = new ArrayList<AnswerEntity>();
			// 获取该学生对该次作业答案
			List<AnswerEntity> answers = answerDao.findByStudentIdAndZuoYeId(stuId, zuoYeClassEntity.getZuoyeId());
			for (AnswerEntity answerEntity : answers) {
				// 根据答案表中的题目编号来获取题目对象
				TitleEntity titleEntity = tiMuDao.findOne(answerEntity.getTitleId());
				// 根据题目对象中的题目类型来进行分类，分别存进不同的答案集合中
				if ("选择题".equals(titleEntity.getTitleType())) {
					answer1.add(answerEntity);
				} else if (titleEntity.getTitleType().equals("判断题")) {
					answer2.add(answerEntity);
				} else if ("代码题".equals(titleEntity.getTitleType())) {
					answer3.add(answerEntity);
				}
			}
			List<Map<String, Object>> score3 = new ArrayList<Map<String, Object>>();
			for (AnswerEntity answerEntity : answer3) {
				Map<String, Object> obj=new HashMap<String, Object>();
				obj.put("score", answerEntity.getScore());
				obj.put("titleId",answerEntity.getTitleId());
				score3.add(obj);
			}
			model.addAttribute("score3", score3);// 选择题答案
			System.out.println("AAA:"+score3);
			model.addAttribute("answer1", answer1);// 选择题答案
			model.addAttribute("answer2", answer2);// 判断题答案
			model.addAttribute("answer3", answer3);// 代码题答案
			System.out.println("编码题中的分数："+answer3);
			model.addAttribute("zuoyeId", zuoYeClassEntity.getZuoyeId());// 判断题答案
			model.addAttribute("studentId", stuId);// 代码题答案
		}
		return "jiaoxue/jx-start-yuejuan";
	}

	@RequestMapping({"/jx-studentinfo", "/jx-studentinfo/{stuId}" })
	public String studentinfo(@PathVariable(name = "stuId", required = false) Long stuId,Model model) {
				//获取未提交作业
				List<Map<String, Object>> maps= zuoyeMappers.findByStudent(stuId);
				//获取未提交考试
				List<Map<String, Object>> maps2= zuoyeMappers.findByStudent2(stuId);
				//获取已提交作业
				List<Map<String, Object>> maps3= zuoyeMappers.findByStudent3(stuId);
				//获取已提交考试
				List<Map<String, Object>> maps4= zuoyeMappers.findByStudent4(stuId);
				//获取提交率
				List<Integer> tijiao = new ArrayList<Integer>();
				List<String> studentName = new ArrayList<String>();
				//查询学生的名字
				String name=studentDao.findOne(stuId).getStudentName();
				model.addAttribute("name", name);
				//查询该学生班级中所有的作业
				List<ZuoYeClassEntity> zuoYeClassEntity=zuoyeClassDao.findByClassId(studentDao.findOne(stuId).getClassId());
				Double x=Double.valueOf(String.valueOf(zuoYeClassEntity.size()));
				//班级下的所有的学生
				List<StudentEntity> studentEntities=studentDao.findByClassId(studentDao.findOne(stuId).getClassId());
				for (StudentEntity studentEntity : studentEntities) {
					//查询当前学生的提交的答案
					List<AnswerEntity> answerEntity=answerDao.cxtijiao(stuId);
					Double y=Double.valueOf(String.valueOf(answerEntity.size()));
					//计算学生的提交率
					double z=y/x;
					NumberFormat num = NumberFormat.getPercentInstance();   
					String rates = num.format(z);  
					//System.out.println("rates"+rates.substring(0, 2));
					if (rates.length()>2) {
						tijiao.add(Integer.valueOf(rates.substring(0, 2)));
					}else {
						tijiao.add(Integer.valueOf(rates));
					}
					studentName.add(studentEntity.getStudentName());
				}
				model.addAttribute("banjiName",JSONArray.toJSONString(classDao.findOne(zuoYeClassEntity.get(0).getClassId()).getClassName()));
				model.addAttribute("tijiao",JSONArray.toJSONString(tijiao));
				model.addAttribute("studentName",JSONArray.toJSONString(studentName));
				/*System.out.println("KK:"+stuId);
				System.out.println("maps:"+maps); 
				System.out.println("maps2:"+maps2);
				System.out.println("maps3:"+maps3);
				System.out.println("maps4:"+maps4);
				*/
				model.addAttribute("maps", maps);
				model.addAttribute("maps2", maps2);
				model.addAttribute("maps3", maps3);
				model.addAttribute("maps4", maps4);
				model.addAttribute("studentinfoId",stuId);
				return "jiaoxue/jx-studentinfo";
	}

	@RequestMapping("/jx-qinshi-list")
	public void qinshiList() {

	}

	@RequestMapping({ "jx-add-qinshi", "jx-add-qinshi/{id}" })
	public String addqinshi(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			QinShiEntity u = qinshiDao.findOne(id);// 根据前台传过来的寝室编号来查询
			if (u != null) {
				// 如果是编辑，则把原有用户信息传回表单页面
				Long studentId = u.getQinshizhang();// 在查询出来寝室长的编号
				if (studentId != null) {
					StudentEntity student = studentDao.findOne(studentId);// 如果寝室长编号不为空，则将寝室长的信息查询出来
					String name = student.getStudentName();
					model.addAttribute("name", name);
				}
				model.addAttribute("qinshi", u);
			}
		}
		return "jiaoxue/jx-add-qinshi";
	}

	@RequestMapping("/jx-jieduan-list")
	public void jieduanList() {

	}

	@RequestMapping({ "jx-add-jieduan", "jx-add-jieduan/{id}" })
	public String addjieduan(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			PhaseEntity phase = phaseDao.findOne(id);
			if (phase != null) {
				model.addAttribute("phase", phase);
			}
		}
		return "jiaoxue/jx-add-jieduan";
	}

	@RequestMapping("/jx-zhangjie-list")
	public String zhangjieList(Model model) {
		Iterable<PhaseEntity> list = phaseDao.findByDelete(1);
		model.addAttribute("zhangjie", list);
		return "jiaoxue/jx-zhangjie-list";
	}

	@RequestMapping({ "/jx-add-zhangjie", "/jx-add-zhangjie/{id}" })
	public String addzhangjie(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			ChapterEntity chapter = zhangJieDao.findOne(id);
			model.addAttribute("zhangjie", chapter);
		}
		Iterable<PhaseEntity> list = phaseDao.findByDelete(1);
		model.addAttribute("phase", list);
		return "jiaoxue/jx-add-zhangjie";
	}

	@RequestMapping("/jx-timu-list")
	public String timuList(Model model) {
		Iterable<PhaseEntity> list = phaseDao.findByDelete(1);
		model.addAttribute("phase", list);
		return "jiaoxue/jx-timu-list";
	}

	@GetMapping("/neirong/{id}")
	@ResponseBody
	public Map<String, Object> zhangjie(@PathVariable(name = "id", required = false) Long id) {
		Map<String, Object> obj = new HashMap<String, Object>();
		obj.put("success", false);
		Iterable<ChapterEntity> list = zhangJieDao.findByPhaseId(id);
		if (list != null) {
			obj.put("message", list);
			obj.put("success", true);
		}
		return obj;
	}

	@RequestMapping({ "/jx-add-timu", "/jx-add-timu/{id}" })
	public String addTimu(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			TitleEntity title = tiMuDao.findOne(id);
			model.addAttribute("timu", title);
		}

		Iterable<PhaseEntity> list = phaseDao.findByDelete(1);
		List<ChapterEntity> x = zhangJieDao.findByPhaseId(1l);
		model.addAttribute("phase", list);
		model.addAttribute("chapter", x);
		return "jiaoxue/jx-add-timu";
	}

	@RequestMapping("/jx-zuoye-list")
	public String zuoyeList(Model model) {
		Iterable<ClassEntity> list = classDao.findByDelete(1);
		Iterable<PhaseEntity> phase = phaseDao.findByDelete(1);
		model.addAttribute("phase", phase);
		model.addAttribute("classList", list);
		return "jiaoxue/jx-zuoye-list";
	}

	@RequestMapping({ "/jx-teacher-buzhi", "/jx-teacher-buzhi/{id}/{name}" })
	public String buzhi(@PathVariable(name = "name", required = false) String name,
			@PathVariable(name = "id", required = false) Long id, Model model) {
		System.out.println("进来了。。。。");
		Long f=null;
		if (id != null) {
			ZuoYeEntity zuoYeEntity = zuoyeDao.findOne(id);// 作业的基本信息
			UserInfoEntity userinfo = zuoYeEntity.getUserinfo();// 布置作业人的信息
			ChapterEntity chapterEntity = zhangJieDao.findOne(zuoYeEntity.getChapterinfo());
			f=chapterEntity.getPhaseId();
			// ChapterEntity chapterEntity=zuoYeEntity.getChapterinfo();//获取章节编号
			PhaseEntity phaseEntity = phaseDao.findOne(chapterEntity.getPhaseId());// 获取阶段编号
			// 获取题型的数量
			Integer x = zuoyeMappers.chaxunXuanZe(id);// 选择题
			Integer y = zuoyeMappers.chaxunPanDuan(id);// 判断题
			Integer z = zuoyeMappers.chaxunDaiMa(id);// 代码题
			List<ZuoYeClassEntity> zuoYeClass = zuoyeClassDao.findByZuoyeId(zuoYeEntity.getZuoyeId());
			List<ClassEntity> AllClass = new ArrayList<ClassEntity>();
			for (ZuoYeClassEntity zuoYeClassEntity : zuoYeClass) {
				ClassEntity classEntity = classDao.findOne(zuoYeClassEntity.getClassId());
				AllClass.add(classEntity);
			}
			model.addAttribute("x", x);
			model.addAttribute("y", y);
			model.addAttribute("z", z);
			model.addAttribute("chapterA", chapterEntity);
			model.addAttribute("phaseB", phaseEntity);
			model.addAttribute("AllClass", AllClass);
			model.addAttribute("zuoye", zuoYeEntity);
			model.addAttribute("userinfo", userinfo);
		}
		Iterable<PhaseEntity> list = phaseDao.findByDelete(1);
		List<ChapterEntity> x=null;
		if (f!=null) {
			 x = zhangJieDao.findByPhaseId(f);
		}else {
			 x = zhangJieDao.findByPhaseId(1l);
		}
		Iterable<ClassEntity> classList = classDao.findByDelete(1);
		model.addAttribute("phase", list);
		model.addAttribute("chapter", x);
		model.addAttribute("classList", classList);
		return "jiaoxue/jx-teacher-buzhi";
	}

	@RequestMapping("/jx-teacher-yuejuan")
	public String teacherYuejuan(Model model) {
		List<Map<String, Object>> maps = zuoyeMappers.yuejuan();
		System.out.println("maps" + maps);
		model.addAttribute("maps", maps);
		return "jiaoxue/jx-teacher-yuejuan";
	}

	@RequestMapping("/jx-student-list")
	public String studentList(Model model) {
		Iterable<ClassEntity> list = classDao.findByDelete(1);
		model.addAttribute("classList", list);
		return "jiaoxue/jx-student-list";
	}

	@RequestMapping({ "/jx-add-student", "/jx-add-student/{id}" })
	public String addStudent(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			StudentEntity studentEntity = studentDao.findOne(id);
			if (studentEntity != null) {
				model.addAttribute("student", studentEntity);
				if (studentEntity.getParentName()!=null) {
					String[] x = studentEntity.getParentName().split("/");
					model.addAttribute("fatherName", x[0]);
					model.addAttribute("motherName", x[1]);
				}
				if (studentEntity.getParentPhone()!=null||"".equals(studentEntity.getParentPhone())) {
					String[] y = studentEntity.getParentPhone().split("/");
					model.addAttribute("fatherPhone", y[0]);
					model.addAttribute("motherPhone", y[1]);
				}
			}
		}
		Iterable<ClassEntity> list = classDao.findByDelete(1);
		model.addAttribute("classList", list);
		return "jiaoxue/jx-add-student";
	}

	@RequestMapping("/jx-zhuanban-list")
	public void zhuanbanList() {

	}

	@RequestMapping({ "/jx-add-zhuanban", "/jx-add-zhuanban/{id}" })
	public String addZhuanBan(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			ZhuanBanEntity zhuanBanEntity = zhuanbanDao.findOne(id);
			ClassEntity oldclass;
			StudentEntity studentEntity;
			if (zhuanBanEntity == null) {// 学生表中的转班
				studentEntity = studentDao.findOne(id);
				oldclass = classDao.findOne(studentEntity.getClassId());
			} else {
				ClassEntity newclass = classDao.findOne(zhuanBanEntity.getNewClassId());// 新班级
				oldclass = classDao.findOne(zhuanBanEntity.getOldClassId());// 旧班级
				studentEntity = studentDao.findOne(zhuanBanEntity.getStudent().getStuId());// 学生
				model.addAttribute("zhuanBanEntity", zhuanBanEntity);
				model.addAttribute("newclass", newclass);
			}
			model.addAttribute("oldclass", oldclass);
			model.addAttribute("studentEntity", studentEntity);
		}
		Iterable<ClassEntity> list = classDao.findByDelete(1);
		model.addAttribute("classList", list);
		return "jiaoxue/jx-add-zhuanban";
	}

	@RequestMapping("/jx-fangtan-list")
	public String fangtanList(Model model) {
		Iterable<ClassEntity> list = classDao.findByDelete(1);
		model.addAttribute("classList", list);
		return "jiaoxue/jx-fangtan-list";

	}

	@RequestMapping({ "/jx-add-fangtan", "/jx-add-fangtan/{id}" })
	public String addFangTan(@PathVariable(name = "id", required = false) Long id, Model model) {
		System.out.println("访谈编号：" + id);
		if (id != null) {
			// 编辑
			FangTanEntity fangTan = fangtanDao.findOne(id);
			StudentEntity student;
			ClassEntity classEntity;
			if (fangTan == null) {
				student = studentDao.findOne(id);
				classEntity = classDao.findOne(student.getClassId());
			} else {
				student = fangTan.getStudent();
				classEntity = classDao.findOne(fangTan.getStudent().getClassId());
				model.addAttribute("fangTan", fangTan);
				model.addAttribute("userInfo", fangTan.getUserId());
			}
			model.addAttribute("student", student);
			model.addAttribute("classEntity", classEntity);
		}
		// 添加
		Iterable<ClassEntity> list = classDao.findByDelete(1);
		model.addAttribute("classList", list);
		return "jiaoxue/jx-add-fangtan";
	}
	//===========================================项目管理===============================================================================

	@RequestMapping("/jx-project-list")
	public String xmgl(Model model) {
		Iterable<PhaseEntity> phase = phaseDao.findByDelete(1);
		model.addAttribute("phaseList", phase);
		return "jiaoxue/jx-project-list";
	}
	

	@RequestMapping({ "/jx-add-project", "/jx-add-project/{id}" })
	public String addProject(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			ProjectEntity pro = projectDao.findOne(id);
			model.addAttribute("project", pro);
		}
		Iterable<PhaseEntity> phase = phaseDao.findByDelete(1);
		model.addAttribute("phaseList", phase);
		return "jiaoxue/jx-add-project";
	}
	
//===========================================团队管理===============================================================================
	//查询班级下面的所有的学生
	@GetMapping("/teamcontent/{id}")
	@ResponseBody
	public Map<String, Object> neirong(@PathVariable(name = "id", required = false) Long id) {
		Map<String, Object> obj = new HashMap<String, Object>();
		obj.put("success", false);
		Iterable<StudentEntity> list = studentDao.findByClassId(id);
		if (list != null) {
			obj.put("message", list);
			obj.put("success", true);
		}
		return obj;
	}
	//查询班级下面的所有的学生除了已选的和组长
		@GetMapping("/teamcontent2/{classId}/{studentId}/{array}")
		@ResponseBody
		public Map<String, Object> neirong2(
				@PathVariable(name = "classId") Long classId,//班级编号
				@PathVariable(name = "studentId") Long studentId,//学生编号
				@PathVariable(name = "array") Long[] array) {//组员编号数组 
			Map<String, Object> obj = new HashMap<String, Object>();
			obj.put("success", false);
			//查询该班级下所有的学生
			List<StudentEntity> list=studentDao.findByClassId(classId);
			List<StudentEntity> list2=new ArrayList<StudentEntity>();
			for (int i = 0; i < array.length; i++) {
				StudentEntity studentEntity=studentDao.findOne(array[i]);
				System.out.println(array[i]+"AA"+studentEntity.getStudentName());
				list2.add(studentEntity);
			}
			StudentEntity studentEntity=studentDao.findOne(studentId);
			list.removeAll(list2);
			list.remove(studentEntity);
			System.out.println("待选学生："+list);
			if (list!=null) {
				obj.put("data", list);
				obj.put("success", true);
			}
			return obj;
		}
		
		//查询班级下面的所有的学生除了已选的和组长
				@GetMapping("/teamcontent3/{classId}/{studentId}")
				@ResponseBody
				public Map<String, Object> neirong3(
						@PathVariable(name = "classId") Long classId,//班级编号
						@PathVariable(name = "studentId") Long studentId//学生编号
						) {//组员编号数组 
					Map<String, Object> obj = new HashMap<String, Object>();
					obj.put("success", false);
					//查询该班级下所有的学生
					List<StudentEntity> list=studentDao.findByClassId(classId);
					List<StudentEntity> list2=new ArrayList<StudentEntity>();
					StudentEntity studentEntity=studentDao.findOne(studentId);
					list.remove(studentEntity);
					System.out.println("待选学生："+list);
					if (list!=null) {
						obj.put("data", list);
						obj.put("success", true);
					}
					return obj;
				}
	
	@RequestMapping("/jx-team-list")
	public String teamList(Model model) {
		Iterable<ClassEntity> classList = classDao.findByDelete(1);
		model.addAttribute("classList", classList);
		return "jiaoxue/jx-team-list";
	}

	@RequestMapping({ "/jx-add-team", "/jx-add-team/{id}" })
	public String addTeam(@PathVariable(name = "id", required = false) Long id, Model model) {
		if (id != null) {
			TeamEntity team = teamDao.findOne(id);
			//根据团队编号来获取班级下的团队
			List<TeamClassEntity> teamClassEntity=teamClassDao.findByTeamEntity(team.getTeamId());
			//获取团队所属的班级
			ClassEntity classEntity=classDao.findOne(teamClassEntity.get(0).getClassEntity());
			//获取班级里面的学生
			List<StudentEntity> list=studentDao.findByClassId(classEntity.getClassId());
			//获取班级里面的学生
			List<StudentEntity> list2=studentDao.findByClassId(classEntity.getClassId());
			//根据团队编号来查询团队中的学生
			List<TeamStudentEntity> teamStudentEntitys=teamStudentDao.findByTeamId(id);
			//用来存放该团队组长的信息
			StudentEntity zuZhang=null;
			//用来存放组员的信息
			List<StudentEntity> zuyuan=new ArrayList<StudentEntity>();
			//用来存放组员和组长的信息
			List<StudentEntity> allStudent=new ArrayList<StudentEntity>();
			
			for (TeamStudentEntity teamStudent : teamStudentEntitys) {
				//根据团队学生中间表中的学生编号来查询学生信息
				StudentEntity student=studentDao.findOne(teamStudent.getStudentId());
				if (teamStudent.getStuidentity().equals("组长")) {
					zuZhang=student;
					allStudent.add(student);//将组长的信息存入allStudent
				}else {
					zuyuan.add(student);
					allStudent.add(student);//将组员的信息存入allStudent
				}
			}
			System.out.println("所有学生的名字：");
			for (StudentEntity studentEntity : list) {
				System.out.println("AAA=======@@@@@"+studentEntity.getStudentName());
			}
			
			System.out.println("组员和组长的名字");
			for (StudentEntity studentEntity : allStudent) {
				System.out.println("BBB=========@@@@@@"+studentEntity.getStudentName());
			}
			
			
			//循环剔除掉组长、组员之后剩下未分配团队学生的信息
			list2.removeAll(allStudent);
			
			for (StudentEntity studentEntity : list2) {
				System.out.println("CCC=======@@@@@"+studentEntity.getStudentName());
			}
			
			System.out.println("list"+list);
			System.out.println("zuZhang"+zuZhang);
			System.out.println("zuyuan"+zuyuan);
			System.out.println("allStudent"+allStudent);
			//获取创建人的信息
			UserInfoEntity userInfoEntity=userInfoDao.findOne(team.getCreateId());
			model.addAttribute("team", team);//保存团队名称
			model.addAttribute("userInfoEntity", userInfoEntity);//保存创建人的编号
			model.addAttribute("classEntity", classEntity);//保存班级的信息
			model.addAttribute("studentList", list);//保存根据班级查询的student信息
			model.addAttribute("studentList2", list2);//保存根据班级查询的student信息
			model.addAttribute("zuZhang", zuZhang);//保存组长的信息
			model.addAttribute("zuyuan", zuyuan);//保存组员的信息
			
		}
		Iterable<ClassEntity> classList = classDao.findByDelete(1);
		model.addAttribute("classList", classList);
		return "jiaoxue/jx-add-team";
	}
	//==========================================================================================================================

	@RequestMapping("/jx-xcy-add")
	public void addProjectChengYuan() {

	}

	@RequestMapping("/bing")
	public void bing(Model model) {
		//录入学生的数量
		List<InputStudentEntity> f=inputStudentDao.chaXunAllInputStudent();
		System.out.println("录入学生的长度是："+f.size());
		//在读中学生的数量
		List<StudentEntity> count1=studentDao.findByStudentState(1+"");
		System.out.println("在读中学生的长度是："+count1.size());
		//已退学学生的数量
		List<StudentEntity> count2=studentDao.findByStudentState(2+"");
		System.out.println("已退学学生的长度是："+count2.size());
		//就业中学生的数量
		List<StudentEntity> count3=studentDao.findByStudentState(3+"");
		System.out.println("就业中学生的长度是："+count3.size());
		//已就业学生的数量
		List<StudentEntity> count4=studentDao.findByStudentState(4+"");
		System.out.println("已就业学生的长度是："+count4.size());
		
		model.addAttribute("inputStudentCount",JSONArray.toJSONString(f.size()));
		model.addAttribute("count1",JSONArray.toJSONString(count1.size()));
		model.addAttribute("count2",JSONArray.toJSONString(count2.size()));
		model.addAttribute("count3",JSONArray.toJSONString(count3.size()));
		model.addAttribute("count4",JSONArray.toJSONString(count4.size()));
	}

	@RequestMapping("/ht-log-class")
	public void logClass() {

	}

	@RequestMapping("/ht-log-check")
	public void logCheck() {

	}

	@RequestMapping("/ht-log-teacher")
	public void logTeacher() {

	}

	@RequestMapping("/ht-log-publish")
	public void logPublish() {

	}
}
